package com.bibrApp.difu.actvity.security_setting_mvp;

import android.content.Context;
import android.text.TextUtils;

import com.bibrApp.difu.Response.LoginLogResBody;
import com.bibrApp.difu.Response.PaySettingResPonseBody;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.utils.EncryptUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class SecuritySettingPresenter extends BasePresenter<ISecuritySettingView> {
    public SecuritySettingPresenter(Context context, ISecuritySettingView iView) {
        super(context, iView);
    }

    public void queryLoginLog(int pageSize , int pageNum ,String userId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageNumber", String.valueOf(pageNum));
        map.put("pageSize", String.valueOf(pageSize));
        map.put("userId",userId);
        RetrofitNet.getInstance()
                .getApi()
                .queryLoginLog(EncryptUtils.encryptNewType(map))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new BaseObserver<Object>(context,false) {

                    @Override
                    protected void onSuccess(Object value) {
                        if (value != null) {
                            String jsonStr = EncryptUtils.objectToJson(value);
                            if(TextUtils.isEmpty(jsonStr)){
                                return;
                            }
                            LoginLogResBody loginLogResBody = new Gson().fromJson(jsonStr,LoginLogResBody.class);
                            iView.successOfLoginLog(loginLogResBody.getList(),loginLogResBody.isHasNextPage());
                        }

                    }
                });
    }

}